home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’90 / Busy Box / Sources / busybox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-14  |  6.2 KB  |  339 lines  |  [TEXT/KAHL]

  1. /* file: busybox.c    */
  2.  
  3. /* 5:59 6/13/90    Started - Larry, Hoover, &Dan
  4.  
  5. */
  6. /* let's keep the functions in alphabetical order,
  7.         except for the individual drawing "objects" - those'll probably
  8.         be in their own source files anywayz    */
  9.  
  10. #include "busybox.h"
  11.  
  12.  
  13. #define    NumMasters    5
  14. #define    BusyWindow    401
  15.  
  16. /* menu stuff*/
  17. SetUpMenus(void);
  18. int HandleMenu(long mResult);
  19. void DoAbout(void);
  20. int MainEvent(void);
  21. DoKeyDownStuff(char theChar,long modify);
  22.  
  23. /* more window stuff */
  24. MenuHandle        myMenus[3];
  25.  
  26.  
  27.  
  28. ObjInfo    stuff[20];
  29.  
  30. WindowPtr    busyWindow;
  31. int16    numObjects;
  32. RgnHandle    tempRgnHandle;    /* for use with GetClip    */
  33.  
  34. void BeBusy(void)    {
  35.     static int16    nextBusy;
  36.  
  37.     switch (nextBusy)    {
  38.         case 0:
  39.             /* do, say, radar    */
  40.             SetUp(1);
  41.             DrawRadarObj(1);
  42.             nextBusy++;
  43.             break;
  44.         case 1:
  45.             /* do, say, heartbeet    */
  46.             SetUp(2);
  47.             DrawSillyBallz(2);
  48.             nextBusy++;
  49.             break;
  50.         /* ... */
  51.         case 2:
  52.             /* do, say, heartbeet    */
  53.             SetUp(3);
  54.             DrawRandomDotObj(3);
  55.             nextBusy++;
  56.             break;
  57.         /* ... */
  58.         case 3:
  59.             SetUp(4);
  60.             DrawFYAHObj(4);
  61.             nextBusy++;
  62.             break;
  63.         /* ... */
  64.         case 4:
  65.             SetUp(5);
  66.             DrawMeterObj(5);
  67.             nextBusy++;
  68.             break;
  69.         /* ... */
  70.         case 5:
  71.             SetUp(6);
  72.             DrawHeartBeatObj(6);
  73.             nextBusy = 0; /* and it all starts over again    */
  74.             break;
  75.         }
  76.     TakeDown(1);    /* kludgey    */
  77. }    /* BeBusy    */
  78.  
  79.  
  80.  
  81. void SetUp(int16 ID)    {
  82.     
  83.     SetClip(stuff[ID].clip);
  84.     SetOrigin(stuff[ID].h, stuff[ID].v);
  85.     /* clip stuff    */
  86. }    /* SetUp    */
  87.  
  88.  
  89. void TakeDown(int16 ID)    {
  90.     SetOrigin(0, 0);
  91. }    /* TakeDown    */
  92.  
  93.  
  94. void StowObjInfo(Rect *tempRect, int16 ID)    {
  95.     RgnHandle    tempRgn;
  96.     
  97.     stuff[ID].rect = *tempRect;
  98.     stuff[ID].h = -tempRect->left;
  99.     stuff[ID].v = -tempRect->top;
  100.     InsetRect(&stuff[ID].rect,-1,-1);
  101.     tempRgn = NewRgn();
  102.     OffsetRect(tempRect, stuff[ID].h, stuff[ID].v);
  103.     RectRgn(tempRgn, tempRect);
  104.     stuff[ID].clip = tempRgn;
  105. }    /* StowObjInfo    */
  106.  
  107.  
  108.  
  109. void InitBusyBox(void)    {
  110.     Rect    tempRect;
  111.     RgnHandle    tempRgn;
  112.     
  113.     busyWindow = GetNewWindow(BusyWindow, nil, (WindowPtr)-1);
  114.     SetPort(busyWindow);
  115.     
  116.     SetRect(&tempRect, 2, 2, 76, 76);
  117.     StowObjInfo(&tempRect, 1);
  118.     InitRadarObj(&tempRect, 1);
  119.  
  120.     SetRect(&tempRect, 2, 79, 76, 161);
  121.     StowObjInfo(&tempRect, 2);
  122.     InitSillyBallz(&tempRect, 2);
  123.  
  124.     SetRect(&tempRect, 2, 164, 76, 236);
  125.     StowObjInfo(&tempRect, 3);
  126.     InitRandomDotObj(&tempRect, 3);
  127.     
  128.     SetRect(&tempRect, 79, 2, 211, 236);
  129.     StowObjInfo(&tempRect, 4);
  130.     InitFYAHObj(&tempRect, 4);
  131.     
  132.     SetRect(&tempRect, 214, 2, 352, 172);
  133.     StowObjInfo(&tempRect, 5);
  134.     InitMeterObj(&tempRect, 5);
  135.     
  136.     SetRect(&tempRect, 214, 175, 352, 236);
  137.     StowObjInfo(&tempRect, 6);
  138.     InitHeartBeatObj(&tempRect, 6);
  139.     
  140.     numObjects = 6;
  141.     
  142.     stuff[0].clip = NewRgn();
  143.     GetClip(stuff[0].clip);    /* get the wide-open clipping region    */
  144. }    /* InitBusyBox    */
  145.  
  146.  
  147.  
  148. void DoSomeUpdateStuff(void)    {
  149.     int16    i;
  150.     
  151.     /* set the clipping wide open    */
  152.     SetClip(stuff[0].clip);
  153.     
  154.     for (i = 1; i <= numObjects; i++)    {
  155.         FrameRect(&stuff[i].rect);
  156.     }
  157. }    /* DoSomeUpdateStuff    */
  158.  
  159.  
  160.  
  161. void InitManagers(int16 numMasters)    {
  162.     int16    i;
  163.     
  164.     InitGraf(&thePort);
  165.     InitFonts();
  166.     InitWindows();
  167.     InitMenus();
  168.     TEInit();
  169.     InitDialogs(nil);
  170.     for (i = 0; i < NumMasters; i++)    {
  171.         MoreMasters();
  172.     }
  173.     FlushEvents( everyEvent, 0 );
  174.     InitCursor();
  175. }    /* InitManagers    */
  176.  
  177.  
  178.  
  179. main()    {
  180.     EventRecord    theEvent;
  181.     
  182.     InitManagers(NumMasters);
  183.     SetUpMenus();
  184.     InitBusyBox();    /* load trig tables, windows, menus, etc...    */
  185.     while(MainEvent());
  186. }    /* main */
  187.  
  188.  
  189. int MainEvent()
  190. {
  191.     EventRecord myEvent;
  192.     WindowPtr whichWindow;
  193.     Rect r;
  194.     
  195.     
  196.     SystemTask();
  197.     if (GetNextEvent(everyEvent, &myEvent)) {
  198.         switch (myEvent.what) {
  199.             case mouseDown:            /* the mouse has been pressed */
  200.                 switch (FindWindow( myEvent.where, &whichWindow )) {
  201.                     case inDesk:    /* in the desktop area */
  202.                         break;
  203.                      case inMenuBar:    /* in the menu bar */
  204.                         return(HandleMenu(MenuSelect(myEvent.where)));
  205.                         break;
  206.                     case inGoAway:    /* in a go away box */
  207.                         break;
  208.                     case inSysWindow:    /* handle a DA or other sys window*/
  209.                         break;
  210.                     case inContent:    /* in the content area of a window */
  211.                         break;
  212.                     case inDrag:
  213.                         SetRect(&r, 0, 0, 5000, 5000);
  214.                         DragWindow(whichWindow, myEvent.where, &r);
  215.                 }
  216.                 break;
  217.             case keyDown:            /* a key is being pressed */
  218.             case autoKey:            /*   and still being pressed */
  219.                 /* pass the character to DoKeyStuff */
  220.                 DoKeyDownStuff(myEvent.message & charCodeMask,myEvent.modifiers);
  221. /* are we going to have any keystuff ?? */
  222.                 break;
  223.             case activateEvt:        /* activate a window */
  224.             
  225.                 break;
  226.             case updateEvt:            /* time to get that new update */
  227.                 DoSomeUpdateStuff();
  228.                 break;
  229.             default:;
  230.                 
  231.         }
  232.     }
  233.     BeBusy();
  234.     HiliteMenu(0);
  235.     return(1);
  236. }
  237.  
  238.  
  239.  
  240. void DoAbout()
  241. {
  242.     Boolean done;
  243.     int theItem;
  244.     DialogPtr AboutPtr;
  245.     int itemType;
  246.     Handle item;
  247.     Rect box;
  248.  
  249.     done = FALSE;
  250.     AboutPtr = GetNewDialog(AboutDlog,0L,(WindowPtr)-1);
  251.     
  252.     while (!done) {
  253.         ModalDialog(0L,&theItem);
  254.         switch (theItem) {
  255.             case OK: 
  256.                 done = TRUE;
  257.                 break;
  258.             case Cancel: 
  259.                 done = TRUE;
  260.                 break;
  261.         }
  262.     }
  263.     DisposDialog(AboutPtr);
  264. }
  265.  
  266. SetUpMenus()
  267. {
  268.     int        i;
  269.     myMenus[appleMenu] = GetMenu(AppleID);
  270.  
  271.     if (ResError()) 
  272.         SysBeep(5);
  273.  
  274.     AddResMenu( myMenus[appleMenu], 'DRVR' );        /* add in the DAs */
  275.     myMenus[fileMenu] = GetMenu(FileID);
  276.     myMenus[editMenu] = GetMenu(EditID);
  277.     for ( (i=appleMenu); (i<=editMenu); i++ ) InsertMenu(myMenus[i], 0) ;
  278.     DrawMenuBar();
  279. }
  280.  
  281.  
  282. int HandleMenu(long mResult)
  283.  
  284. {
  285.     int    theItem, theChoice, temp;
  286.     Str255    name;
  287.     WindowPeek wPtr;
  288.  
  289.     theItem = LoWord(mResult);
  290.     switch (HiWord(mResult)) {
  291.         case AppleID:                /* handle  menu choices */
  292.             switch (theItem) {
  293.                 case appleabout:
  294.                     DoAbout();
  295.                     break;
  296.                 default:
  297.                     GetItem(myMenus[appleMenu], theItem, &name);
  298.                     OpenDeskAcc( &name );
  299.                     break;
  300.             }
  301.             break;
  302.         case FileID:        /* handle file menu choices */
  303.             switch (theItem) {
  304.                 case quitCmd:        /* all done, let's go pick up some chicks */
  305.                     ExitToShell();
  306.                     break;
  307.             }
  308.             break;
  309.         case EditID:                /* handle edit menu choices */
  310.             if (SystemEdit(theItem-1)==0) {
  311.                 wPtr = (WindowPeek) FrontWindow();
  312.                 switch (theItem) {
  313.                     case cutCmd:
  314.                         break;
  315.                     case copyCmd:
  316.                         break;
  317.                     case pasteCmd:
  318.                         break;
  319.                     case clearCmd:
  320.                         break;
  321.                     default: 
  322.                         break;
  323.                 }
  324.             }
  325.             break;
  326.             
  327.     }
  328.     return(1);
  329. }
  330.  
  331.  
  332. DoKeyDownStuff(char theChar,long modify)
  333. {
  334.     if ((modify & cmdKey) != 0)        /*check for control key down*/
  335.         HandleMenu(MenuKey(theChar));        /*true, call Menu Mgr.*/
  336. }
  337.  
  338.  
  339.